package iut2.server;

import java.util.ArrayList;

import iut2.client.GreetingService;
import iut2.shared.Troll;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {

	public ArrayList<Troll> greetServerGet() throws IllegalArgumentException {
		ArrayList<Troll> build = new ArrayList<Troll>();
		
		try{
			XMLParser xml = new XMLParser(this.getServletContext().getRealPath("troll-edit-12-11-2012.xml"));
			build = xml.getTrollFromXML();
		}
		catch(Exception exp){  }
		return build;
	}
	
	public boolean greetServerSet(ArrayList<Troll> trollList) throws IllegalArgumentException {
		try{
			
			XMLParser xml = new XMLParser(this.getServletContext().getRealPath("test.xml"));
			return xml.setTrollToXML(trollList);
			
		}
		catch(Exception exp){ System.out.println(exp.getMessage()); return false; }
	}
}
